

#include <cstdlib>
#include<iostream>
#include <locale>
#include "compile_run.hpp"
#include"../comm/httplib.h"

using namespace ns_compile_run;
using namespace httplib;

void Usage(std::string proc)
{
    std::cout<<"Usage: "<<"\n\t"<<proc<<" port"<<std::endl;
}

int main(int argc,char *argv[])
{
    if(argc<2)
    {
        Usage(argv[0]);
        return 1;
    }
   
    Server cr_ser;

    cr_ser.Get("/hello",[](const Request &req, Response &resp){
    // 用来进行基本测试
    resp.set_content("hello httplib,你好 httplib!", "text/plain;charset=utf-8");
    });


    cr_ser.Post("/Compile_Run",[](const Request& req,Response& res){
        //用户使用json串进行服务请求
        std::string in_json = req.body;
        std::string out_json;
        if(!in_json.empty())
        {
            Compile_Run::start(in_json,&out_json);
            res.set_content(out_json,"application/json;charset=utf-8");
        }

    });
    cr_ser.listen("0.0.0.0",atoi(argv[1]));
    return 0;
}





/*int main(int argc, char *argv[])
{

    Server svr;
    svr.Get("/hello",[](const Request &req, Response &resp){
    // 用来进行基本测试
    resp.set_content("hello httplib,你好 httplib!", "text/plain;charset=utf-8");
    });

    svr.listen("0.0.0.0", 8080); //启动http服务
    //svr.set_base_dir("./wwwroot");

    return 0;
}*/



// int main()
// {
//     Server svr;
//     svr.listen("0.0.0.0", 8080);//启动http服务；
//     return 0;
// }





// int main()
// {
//     //std::locale::global(std::locale("en_US.UTF-8"));
//     setlocale(LC_ALL, "");
//     std::string in_json;
//     Json::Value in_value;
//     //R"()", raw string
//     in_value["code"] = R"(#include<iostream>
//     int main(){ std::cout<<"hello run_complie"<<std::endl;})";
//     in_value["input"] = "";
//     in_value["cpu_limit"] = 1;
//     in_value["mem_limit"] = 10240;
//     Json::FastWriter writer;
//     in_json = writer.write(in_value);
//     std::cout << in_json << std::endl;
//     //这个是将来给客户端返回的json串
//     std::string out_json;
//     Compile_Run::start(in_json, &out_json);
//     std::cout << out_json << std::endl;
//     return 0;
// }






/*#include<iostream>

#include "compile_run.hpp"
using namespace ns_compile_run;

int main()
{

    std::string in_json;
    Json::Value in_value;
    in_value["code"] = R"(#include<iostream>
int main(){
  std::cout << "你可以看见我了" << std::endl;
  return 0;
})";
    in_value["input"] = "";
    in_value["cpu_limit"] = 1;
    in_value["mem_limit"] = 10240 * 3;
    Json::FastWriter writer;
    in_json = writer.write(in_value);
    std::cout << in_json << std::endl;
    std::string out_json;
    Compile_Run::start(in_json, &out_json);
    std::cout << out_json << std::endl;
    return 0;
}*/







/*#include"compiler.hpp"
#include"runner.hpp"

using namespace ns_compile;
using namespace ns_runner;
int main()
{
    std::string code="code";
    Compiler::Compile(code);
    //Runner::Run(code,);

    return 0;
}*/